//
//  SynDetailsFifthCell.m
//  XDBaseFrameWork
//
//  Created by XD-XY on 10/20/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "SynDetailsFifthCell.h"

@implementation SynDetailsFifthCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self makeViews];
    }
    return self;
}

-(void)makeViews
{
    self.backgroundColor = [UIColor whiteColor];
    
    self.firstIV = [UIImageView initImageViewRect:CGRectMake(5, 0, 100, 100) andImage:nil andUserInteractionEnabled:YES];
   
    self.secondIV = [UIImageView initImageViewRect:CGRectMake(width_x(_firstIV)+5, 0, 100, 100) andImage:nil andUserInteractionEnabled:YES];
    
    self.thirdIV = [UIImageView initImageViewRect:CGRectMake(width_x(_secondIV)+5, 0, 100, 100) andImage:nil andUserInteractionEnabled:YES];
    
    [self.contentView addSubview:_firstIV];
    [self.contentView addSubview:_secondIV];
    [self.contentView addSubview:_thirdIV];

    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(breviaryImageClick:)];
    [_firstIV addGestureRecognizer:tap];
    
    UITapGestureRecognizer * tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(breviaryImageClick:)];
    [_secondIV addGestureRecognizer:tap2];
    
    UITapGestureRecognizer * tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(breviaryImageClick:)];
    [_thirdIV addGestureRecognizer:tap3];
    
    _firstIV.backgroundColor = UIColorFromRGB(0xeaeaea);
    _secondIV.backgroundColor = UIColorFromRGB(0xeaeaea);
    _thirdIV.backgroundColor = UIColorFromRGB(0xeaeaea);
    
    _firstIV.hidden = YES;
    _secondIV.hidden = YES;
    _thirdIV.hidden = YES;
    
    _firstIV.tag = 10001;
    _secondIV.tag = 10002;
    _thirdIV.tag = 10003;
    
    _firstIV.layer.masksToBounds = YES;
    _firstIV.layer.rasterizationScale = [UIScreen mainScreen].scale;
    _firstIV.layer.shouldRasterize   = YES;
    _firstIV.clipsToBounds = YES;
    _firstIV.contentMode = UIViewContentModeScaleAspectFill;//跟微信一样 填充
    
    _secondIV.layer.masksToBounds = YES;
    _secondIV.layer.rasterizationScale = [UIScreen mainScreen].scale;
    _secondIV.layer.shouldRasterize   = YES;
    _secondIV.clipsToBounds = YES;
    _secondIV.contentMode = UIViewContentModeScaleAspectFill;//跟微信一样 填充
    
    _thirdIV.layer.masksToBounds = YES;
    _thirdIV.layer.rasterizationScale = [UIScreen mainScreen].scale;
    _thirdIV.layer.shouldRasterize   = YES;
    _thirdIV.clipsToBounds = YES;
    _thirdIV.contentMode = UIViewContentModeScaleAspectFill;//跟微信一样 填充


}

-(void)setDataDict1:(NSMutableDictionary *)dataDict1
{
    if (_dataDict1){
        _dataDict1 =nil;
    }
    if (![[dataDict1 allKeys] count]){
        _firstIV.hidden = YES;
        _firstIV.image = nil;
        return;
    }
    
    _dataDict1 = [[NSMutableDictionary alloc] initWithDictionary:dataDict1];
    [_firstIV sd_setImageWithURL:_dataDict1[@"Photo"]];
    _firstIV.hidden = NO;
}

-(void)setDataDict2:(NSMutableDictionary *)dataDict2
{
    if (_dataDict2){
        _dataDict2 =nil;
    }
    if (![[dataDict2 allKeys] count]){
        _secondIV.hidden = YES;
        _secondIV.image = nil;
        return;
    }
    
    _dataDict2 = [[NSMutableDictionary alloc] initWithDictionary:dataDict2];
    [_secondIV sd_setImageWithURL:_dataDict2[@"Photo"]];
    _secondIV.hidden = NO;
}

-(void)setDataDict3:(NSMutableDictionary *)dataDict3
{
    if (_dataDict3){
        _dataDict3 =nil;
    }
    if (![[dataDict3 allKeys] count]){
        _thirdIV.hidden = YES;
        _thirdIV.image = nil;
        return;
    }
    
    _dataDict3 = [[NSMutableDictionary alloc] initWithDictionary:dataDict3];
    [_thirdIV sd_setImageWithURL:_dataDict3[@"Photo"]];
    _thirdIV.hidden = NO;
}

-(void)breviaryImageClick:(UITapGestureRecognizer *)sender
{
    UIImageView * iv =(UIImageView *) sender.view;
    NSString * urlstring;
    if(iv.tag == _firstIV.tag){
        urlstring = _dataDict1[@"Photo"];
    }
    if (iv.tag == _secondIV.tag){
        urlstring = _dataDict2[@"Photo"];

    }
    if (iv.tag == _thirdIV.tag){
        urlstring = _dataDict3[@"Photo"];

    }
    [_delegate browsingLargerImageWithIV:iv andUrl:urlstring];
    
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
